-
Notifications
You must be signed in to change notification settings - Fork 763
Delete non-approved revisions on user deletion #6567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
akatsoulas
commented
Mar 17, 2025
- Delete docs without revisions on user deletion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements logic to delete documents without approved revisions during user deletion and reassign all remaining revisions to SUMO_BOT.
- Updates the user deletion handler to conditionally delete documents if they lack an approved revision and remove non‐approved revisions otherwise.
- Adds a new test case in the wiki tests to cover the behavior for non‐approved revision handling on user deletion.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
kitsune/wiki/tests/test_handlers.py | Added a test case to verify the deletion of documents without approved revisions and proper handling of non-approved revisions. |
kitsune/wiki/handlers.py | Updated the on_user_deletion handler to delete documents with no approved revisions and delete or reassign non-approved revisions accordingly. |
kitsune/wiki/handlers.py
Outdated
for revision in non_approved_revisions: | ||
document = revision.document | ||
# If current_revision is None, the document has no approved revisions | ||
if document.current_revision is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a document has multiple non-approved revisions, the loop may attempt to delete the same document multiple times, which could potentially lead to errors or unexpected behavior. Consider grouping non-approved revisions by document to ensure each document is processed only once.
Copilot uses AI. Check for mistakes.
kitsune/wiki/handlers.py
Outdated
@@ -19,5 +19,15 @@ def on_user_deletion(self, user: User) -> None: | |||
document.contributors.add(*content_group.user_set.all()) | |||
document.contributors.remove(user) | |||
|
|||
non_approved_revisions = Revision.objects.filter(creator=user, is_approved=False) | |||
|
|||
for revision in non_approved_revisions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this loop be replaced with the following instead?
# First delete all of the docs that have no current revision but one or more of the users' unapproved revisions.
Document.objects.filter(current_revision__isnull=True, revisions__in=non_approved_revisions).delete()
# Next, delete all of the users' unapproved revisions that were not cascade deleted above.
non_approved_revisions.delete()
9750c73
to
4b085d1
Compare
@escattone PR updated |
4b085d1
to
a19e2f7
Compare
* Delete docs without revisions on user deletion